<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
$_option = $this->getOption();
$class = ($_option->getIsRequire()) ? ' required' : '';
?>

<div class="field<?php if ($_option->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_AREA) {
    echo ' textarea';
} ?><?php echo $class ?>">
    <label class="label">
        <span><?php echo $this->escapeHtml($_option->getTitle()) ?></span>
        <?php echo $this->getFormatedPrice() ?>
    </label>

    <div class="control">
        <?php if ($_option->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_FIELD): ?>
            <?php $_textValidate = null;
            if ($_option->getIsRequire()) {
                $_textValidate['required'] = true;
            }
            if ($_option->getMaxCharacters()) {
                $_textValidate['maxlength'] = $_option->getMaxCharacters();
            }
            ?>
            <input type="text"
                   id="options_<?php echo $_option->getId() ?>_text"
                   class="input-text product-custom-option"
                   <?php if (!empty($_textValidate)) echo 'data-validate=' . json_encode($_textValidate); ?>
                   name="options[<?php echo $_option->getId() ?>]"
                   value="<?php echo $this->escapeHtml($this->getDefaultValue()) ?>"/>
        <?php elseif ($_option->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_AREA): ?>
            <?php $_textAreaValidate = null;
            if ($_option->getIsRequire()) {
                $_textAreaValidate['required'] = true;
            }
            if ($_option->getMaxCharacters()) {
                $_textAreaValidate['maxlength'] = $_option->getMaxCharacters();
            }
            ?>
            <textarea id="options_<?php echo $_option->getId() ?>_text"
                      class="product-custom-option"
                      <?php if (!empty($_textAreaValidate)) echo 'data-validate=' . json_encode($_textAreaValidate); ?>
                      name="options[<?php echo $_option->getId() ?>]"
                      rows="5"
                      cols="25"><?php echo $this->escapeHtml($this->getDefaultValue()) ?></textarea>
        <?php endif; ?>
        <?php if ($_option->getMaxCharacters()): ?>
            <p class="note"><?php echo __('Maximum number of characters:') ?>
                <strong><?php echo $_option->getMaxCharacters() ?></strong></p>
        <?php endif; ?>
    </div>
</div>
